home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15450 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: news.informatik.uni-kiel.de!ma
  2. From: ma@informatik.uni-kiel.de (Martin Ameskamp)
  3. Newsgroups: comp.lang.c++
  4. Subject: Null pointers again (Was: Is this a memory leak?)
  5. Date: 5 Apr 1996 15:41:38 GMT
  6. Organization: Dept. of Computer Science, University of Kiel, FRG
  7. Message-ID: <4k3evi$rpn@gutemine.informatik.uni-kiel.de>
  8. References: <4jv214$gv7@insosf1.netins.net> <4k02v5$tu7@grimsel.zurich.ibm.com> <4k2vku$s82@werple.net.au> <4k39f5$lhn@grimsel.zurich.ibm.com>
  9. NNTP-Posting-Host: rigel.informatik.uni-kiel.de
  10.  
  11. In <4k39f5$lhn@grimsel.zurich.ibm.com> wgk@zurich.ibm.com (Keith Whittingham) writes:
  12. >>The use of 0 as a pointer is not the address 0x000. It is a null pointer
  13. >>as defined by the language. Implementations are not even required to use a
  14. >>bit pattern of all zeroes as a null pointer. They can use any value they
  15. >>like, as long as it will not also be used as a real address. Furthermore,
  16. >>rather than being a quirk of implementation, the language guarantees that
  17. >>deleting a null pointer will do nothing. 
  18.  
  19.     Correct.
  20.  
  21. >Er, I don't think I agree. 
  22.  
  23. >The line of code (if I remember correctly) was:
  24.  
  25. >   bury = 0;
  26.  
  27. >'bury' being a pointer to some element. bury *is* a pointer and it is 
  28. >assigned the value 0. 0 is the same as 0x0000. The line of code:
  29.  
  30. >   bury = NULL;
  31.  
  32. >may of course set bury to some other value.
  33.  
  34.     No. 0 is special in regard to pointers (regardless of the spelling,
  35.     be it 0, 0x000 or NULL (beware of casts with NULL)). Instead of
  36.     arguing, I'll quote the ARM (4.6, pointer conversions):
  37.  
  38.     "A constant expression that evaluates to zero is converted to
  39.     a pointer, commonly called the null pointer. It is guaranteed
  40.     that this value will produce a pointer distinguishable from a
  41.     pointer to any object or function."
  42.  
  43.     Annotation: "Note that the null pointer need not be represented
  44.     by the same bit pattern as the integer 0."
  45.  
  46. >In the real world most, if not all, compilers (I know of no exceptions) 
  47. >use the value 0 for a NULL pointer. As the original poster is trying 
  48. >to understand why his compiler is behaving the way it is I don't think
  49. >that things need to be complicated with pathological cases.
  50.  
  51.     See section 5.17 of the comp.lang.c FAQ for a long list of machines
  52.     that do not represent the null pointer as aal zeroes.
  53.     (The only topic of section 5 is null pointers from all angles,
  54.     it can be found at
  55.     ftp://rtfm.mit.edu/pub/usenet-by-hierarchy/comp/lang/c/C-FAQ-list)
  56.     (Yes, I know this is compl.lang.c++...)
  57.  
  58.     Martin
  59.